package com.itheima.a10threadsafe2;

public class MyRunnable implements Runnable {
    static int count = 0;
    @Override
    public void run() {

        while(true){
            if(method())
                break;
        }
    }

    public synchronized boolean method(){
            if (count < 100) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                count++;
                System.out.println(Thread.currentThread().getName() + "@" + count);
            } else {
                return true;
            }
        return false;
    }
}
